//
//  YNSPayCCell.m
//  HNBaseProject
//
//  Created by TR on 2024/7/25.
//

#import "YNSPayCCell.h"

@implementation YNSPayCCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame])
    {
        self.backgroundColor = [UIColor whiteColor];
        self.bgView = [[UIView alloc]init];
        self.bgView.backgroundColor = [UIColor colorWithHexString:@"#E8F4FE"];
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 7;
        [self addSubview:self.bgView];
        [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.bottom.offset(0);
        }];
        
        self.tLab = [[UILabel alloc]init];
//        self.tLab.text = @"小堆钻石";
        self.tLab.textColor = [UIColor colorWithHexString:@"#2176BC"];
        self.tLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.tLab];
        [self.tLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(18);
            make.centerX.equalTo(self.bgView.mas_centerX).offset(0);
        }];
        
        self.zsImageV = [[UIImageView alloc]init];
        self.zsImageV.image = [UIImage imageNamed:@"pay_zs_b"];
        [self.bgView addSubview:self.zsImageV];
        [self.zsImageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.tLab.mas_bottom).offset(5);
            make.centerX.equalTo(self.bgView.mas_centerX).offset(0);
            make.width.height.offset(35);
        }];
        
        self.numLab = [[UILabel alloc]init];
       
        self.numLab.textColor = [UIColor colorWithHexString:@"#000000"];
        self.numLab.font = [UIFont systemFontOfSize:22 weight:UIFontWeightBold];
        [self.bgView addSubview:self.numLab];
        [self.numLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.zsImageV.mas_bottom).offset(5);
            make.centerX.equalTo(self.bgView.mas_centerX).offset(0);
        }];
        
        
        self.labBg = [[UIView alloc] init];
        [self.bgView addSubview:self.labBg];
        self.labBg.layer.masksToBounds= YES;
        self.labBg.layer.cornerRadius = 12;
        [self.labBg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.numLab.mas_bottom).offset(5);
            make.left.offset(9);
            make.right.offset(-9);
            make.height.offset(24);
        }];
        
        CAGradientLayer *gl = [CAGradientLayer layer];
        gl.frame = CGRectMake(0, 0, (kScreenW-50)/3-18, 24);
        gl.startPoint = CGPointMake(1, 0.45);
        gl.endPoint = CGPointMake(0, 0.5);
        gl.colors = @[(__bridge id)[UIColor colorWithHexString:@"#FF7127"].CGColor, (__bridge id)[UIColor colorWithHexString:@"#FFC400"].CGColor];
        gl.locations = @[@(0), @(1.0f)];
        [self.labBg.layer addSublayer:gl];
        
        self.moneyLab = [[UILabel alloc]init];
        self.moneyLab.textColor = [UIColor whiteColor];
        self.moneyLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.moneyLab];
        
        [self.moneyLab mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(self.numLab.mas_bottom).offset(5);
//            make.left.offset(9);
//            make.right.offset(-9);
//            make.height.offset(24);
            make.center.mas_equalTo(self.labBg);
        }];
    }
    return self;
}

- (void)layoutIfNeeded {
    [super layoutIfNeeded];
}

- (void)reloadCellWithDict:(NSDictionary *)dict select:(BOOL)select {
    self.numLab.text =dict[@"count"];
    self.moneyLab.text = [NSString stringWithFormat:@"USD $%@",dict[@"money"]];
    if (select) {
        self.bgView.backgroundColor = [UIColor colorWithHexString:@"#FFF5DB"];
        self.bgView.layer.borderWidth = 2;
        self.bgView.layer.borderColor = [UIColor colorWithHexString:@"#FFD500"].CGColor;
    } else {
        self.bgView.backgroundColor = [UIColor colorWithHexString:@"#E8F4FE"];
        self.bgView.layer.borderWidth = 2;
        self.bgView.layer.borderColor = [UIColor colorWithHexString:@"#E8F4FE"].CGColor;
    }
}

@end
